import axios from 'axios';

axios.interceptors.request.use(
  config => config,
  error => Promise.reject(error),
);

axios.interceptors.response.use(
  response => response,
  error => Promise.reject(error),
);

const withTimeoutAxios = axios.create({
  timeout: 5000,
});

export async function postRequest(...args: Parameters<typeof axios.post>) {
  const result = await withTimeoutAxios.post(...args);
  return result.data;
}

export async function getRequest(...args: Parameters<typeof axios.get>) {
  const result = await withTimeoutAxios.get(...args);
  return result.data;
}

export async function deleteRequest(...args: Parameters<typeof axios.delete>) {
  const result = await withTimeoutAxios.delete(...args);
  return result.data;
}

export async function putRequest(...args: Parameters<typeof axios.put>) {
  const result = await withTimeoutAxios.put(...args);
  return result.data;
}
